package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.constant.Constant;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

/**
 * @author Neuedu-远哥
 * @version 1.0
 * @date 2021/12/3 14:14
 */
public class Power extends AbstractMapleStoryObject {

    {
        // 加载图片
        images = new Image[10];
        for (int i = 0; i < images.length; i++) {
            images[i] = ImageUtil.getImageByKey("power" + i);
        }
    }

    public int power;

    public Power() {
        this.speed = 5;
    }

    public Power(MapleStoryClient msc, int x, int y) {
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.power = msc.hero.attack;
    }

    @Override
    public void draw(Graphics g) {
        if (!live) {
            msc.powers.remove(this);
            return;
        }
        if(this.power >= Constant.GAME_MAX_POWER){
            this.power = Constant.GAME_MAX_POWER;
        }
        // 画    1356
        // 先拿到Hero的攻击力
        int power = this.power;
        int units = power % 10; // 6
        power = power / 10;// 135
        int tens = power % 10;// 5
        power = power / 10;// 13
        int hundreds = power % 10;// 3
        power = power / 10;// 1
        int thousands = power;
        /*String strPower = String.valueOf(power);
        for(int i=0;i<strPower.length();i++){

        }*/
        // 只有个位
        if (thousands == 0 && hundreds == 0 && tens == 0) {
            g.drawImage(images[units], x + msc.background.x, y, null);
        } else if (thousands == 0 && hundreds == 0) {
            g.drawImage(images[units], x + msc.background.x, y, null);
            g.drawImage(images[tens], x + msc.background.x - 31, y, null);
        } else if (thousands == 0) {
            g.drawImage(images[units], x + msc.background.x, y, null);
            g.drawImage(images[tens], x + msc.background.x - 31, y, null);
            g.drawImage(images[hundreds], x + msc.background.x - 62, y, null);
        } else {
            g.drawImage(images[units], x + msc.background.x, y, null);
            g.drawImage(images[tens], x + msc.background.x - 31, y, null);
            g.drawImage(images[hundreds], x + msc.background.x - 62, y, null);
            g.drawImage(images[thousands], x + msc.background.x - 93, y, null);
        }

        move();
    }

    @Override
    public void move() {
        this.y -= speed;
        if (this.y <= 300) {
            this.live = false;
        }
    }
}
